package com.gan.springcloud.controller;

import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

@Log4j2
@ResponseBody
@RestController
public class TestController {

    @Autowired
    private RestTemplate restTemplate;

    /****
     * test1 test2 是spring boot  的知识点 template 的不同获取方式
     *
     */

    @RequestMapping(value = "/test1", method = RequestMethod.GET)
    public Map<String,Object> test1() {
        Map<String,Object> account = new HashMap<>();
        log.info("---------消费者开始------------");
        //调用服务
        account = restTemplate.getForObject("http://goods-provider/getAccount", HashMap.class);//去调服务提供者
        log.info("---------消费者结束--------account{}----",account);
        return account;
    }

    /*@RequestMapping(value = "/test2", method = RequestMethod.GET)
    public Map<String,Object> test2(@RequestBody String app) {
        System.out.println("/test2/{app} --> " + app);
        return restTemplate.getForObject("http://goods-provider/setAccount/" + app, HashMap.class);
    }*/


    @GetMapping("/test3/{app}")
    public Map<String,Object> test3(@PathVariable("app") String app) {
        System.out.println("/test2/{app} --> " + app);
        return restTemplate.getForObject("http://goods-provider/setAccount/" + app, HashMap.class);
    }
}
